//
//  SignViewController.m
//  PublicInfo
//
//  Created by enghou on 2018/1/3.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "SignViewController.h"
#import "LXCalendarView.h"
#import "NetWorkerManager+SignRelated.h"
#import "SignSuccessViewController.h"
#import "NSDate+Category.h"
@interface SignViewController ()
@property (weak, nonatomic) IBOutlet LXCalendarView *signView;
@property (weak, nonatomic) IBOutlet UILabel *weekLabel;
@property (weak, nonatomic) IBOutlet UILabel *monthLabel;
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;

@end

@implementation SignViewController{
    NSInteger weekcount;
    NSInteger monthcount;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.signView.selectBlock = ^(NSInteger year, NSInteger month, NSInteger day) {
        //点击发起网络请求
        [[NetWorkerManager sharedInstance]signActionSuccessBlock:^(BaseModel *model) {
            if (model.success) {
                //更新天数，更新月数
                [self getScore];
            }
        } failBlock:^(NSInteger code) {
        }];
    };
    [self getSignList];
    // Do any additional setup after loading the view.
}

-(void)getSignList{
    NSDate *date = [NSDate date];
    NSString *dateStr = [date dateStrOnlyYearAndMonth];
    [self beginLoading];
    [[NetWorkerManager sharedInstance]signMonthListWithDate:dateStr successBlock:^(BaseModel *model) {
        if (model.success) {
            [self endLoading];
            [self.signView configChoosenWithSignList:model.list];
            NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"本月签到%.2li天",model.list.count] attributes:@{NSForegroundColorAttributeName: [UIColor blackColor],NSFontAttributeName: [UIFont systemFontOfSize:24]}];
            [str addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:32]} range:NSMakeRange(4, 2)];
            self.scoreLabel.attributedText = str;
        }
    } failBlock:^(NSInteger code) {
        
    }];
}

-(void)getScore{
    [self beginLoading];
    [[NetWorkerManager sharedInstance]getMyScoreSuccessBlock:^(BaseModel *model) {
        if (model.success) {
            [self endLoading];
        }
    } failBlock:^(NSInteger code) {
//        [self endLoadingWithPrompt:kNetWorkFail success:NO];
    }];
}

@end
